<?php
class Sosweb_Util_Common_String
{
	public static function startsWith($string, $char)
	{
	    $length = strlen($char);
	    return (substr($string, 0, $length) === $char);
	}
	
	public static function endsWith($string, $char)
	{
	    $length = strlen($char);
	    $start =  $length *-1; //negative
	    return (substr($string, $start, $length) === $char);
	}		
	
	public static function prepareStringFragment($string, $fragmentLenght = null)
	{
		if ($fragmentLenght == null)
		{
			$fragmentLenght = Sosweb_Const_ProfitmaniaConst::$FIRST_PAGE_CONTENT_LENGTH;
		}
		
		if (strlen($string) > $fragmentLenght)
		{
			$maxString = substr($string, 0, $fragmentLenght);
			$lastSpacePosition = strrpos($maxString, ' ');
			
			return substr($maxString, 0, $lastSpacePosition).'...';
		}
		else
		{
			return $string;
		} 
	}
}